﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Xml;
using System.Xml.XPath;
using System.Collections;
using System.Configuration;

//AUI Model Component
using AdaptiveHelpDesk.AUI_Model_Components.Watcher.Combo_box;

namespace AdaptiveHelpDesk.AUI_Model_Components.Analysis_Engine
{
    class AnalyzeSkillLevel
    {

        #region VARIABLES

            SqlConnection con = null;
            SqlDataReader rdr = null;
            StoredProcedures sp = new StoredProcedures();


            XmlElement InteractionFeatures;

            XmlElement LowlevelMotionCharact;

            XmlElement InteractionTechn;

            XmlElement PerformanceM;


            ArrayList arrayNoSol = new ArrayList();
            ArrayList arraySol = new ArrayList();

        #endregion



        #region OPEN CONNECTION

            private void openConnection()
            {
                try
                {
                    ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[3];
                    if (settings != null)
                    {
                        con = new SqlConnection(settings.ConnectionString);
                        con.Open();
                    }
                }
                catch (SqlException ex)
                {                    
                    throw ex;
                }               


                //con = new SqlConnection("Data Source=" + System.Environment.MachineName + "\\SQLExpress;Initial Catalog=ISD;Integrated Security=True");
                //con = new SqlConnection("Data Source=ROCABEE;Initial Catalog=ISD;Integrated Security=True");
               
            }

            #endregion

        
    
        #region GET USER MODEL XML SO THAT IT CAN BE ANALYSED


            public ArrayList getArrayUserModelComboBoxXML(string UID, string getStoreProcedureName, string DisplaySol)
            {
                    try
                    {
                        openConnection();
                        SqlCommand cmd = new SqlCommand(getStoreProcedureName, con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@userID", UID));
                        cmd.Parameters.Add(new SqlParameter("@DisplaySol", DisplaySol));

                        rdr = cmd.ExecuteReader();

                        ArrayList arrayPFs = new ArrayList();

                        while (rdr.Read())
                        {
                            arrayPFs.Add(rdr[0]);
                        }


                        return arrayPFs;
                    }
                    finally
                    {
                        if (con != null)
                        {
                            con.Close();
                        }
                        if (rdr != null)
                        {
                            rdr.Close();
                        }
                    }
                }



            public ArrayList getArrayUserModelComboBoxXMLExperts(string getStoreProcedureName, string DisplaySol)
            {
                try
                {
                    openConnection();
                    SqlCommand cmd = new SqlCommand(getStoreProcedureName, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@DisplaySol", DisplaySol));

                    rdr = cmd.ExecuteReader();

                    ArrayList arrayPFs = new ArrayList();

                    while (rdr.Read())
                    {
                        arrayPFs.Add(rdr[0]);
                    }


                    return arrayPFs;
                }
                finally
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                    if (rdr != null)
                    {
                        rdr.Close();
                    }
                }
            }



            public ArrayList getArrayUserModelXML_Analysis(string UID, string getStoreProcedureName)
            {
                try
                {
                    openConnection();
                    SqlCommand cmd = new SqlCommand(getStoreProcedureName, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@userID", UID));

                    rdr = cmd.ExecuteReader();

                    ArrayList arrayPFs = new ArrayList();

                    while (rdr.Read())
                    {
                        arrayPFs.Add(rdr[0]);
                    }


                    return arrayPFs;
                }
                finally
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                    if (rdr != null)
                    {
                        rdr.Close();
                    }
                }
            }
         
        
        #endregion



        #region T-SCORE 


            public ArrayList getIMs(string UID, string StoredProcedueName,string StoredProcedueNameExperts, string DisplaySol, decimal SumPF01TotalTime, decimal SumPF02YMouseVelocity, decimal SumPF03YMouseAcceleration, decimal SumPF04DwellTime, decimal SumPF05AverageDwellTime, decimal SumPF06NrItemsVisited, decimal SumPF07UniqueItemsVisited, decimal SumPF08SelectionTime, decimal SumPF09KLMDifference, decimal SumPF10KLMRatio)
            {

                #region Mean Variables USER

                    //needed for mean
                    decimal SumTotalTimeUser = 0;
                    decimal SumYMouseVelocityUser = 0;
                    decimal SumYMouseAccelerationUser = 0;
                    decimal SumDwellTimeUser = 0;
                    decimal SumAveDwellTimeUser = 0;
                    decimal SumNrItemsUser = 0;
                    decimal SumUniqueItemsUser = 0;
                    decimal SumSelectionTimeUser = 0;
                    decimal SumKLMDiffUser = 0;
                    decimal SumKLMRatioUser = 0;

                #endregion


                #region STD Variables ALL USERS

                //needed for std dev
                double TotalTimeSTDAll = 0;
                double YMouseVelocitySTDAll = 0;
                double YMouseAccelerationSTDAll = 0;
                double DwellTimeSTDAll = 0;
                double AveDwellTimeSTDAll = 0;
                double NrItemsSTDAll = 0;
                double UniqueItemsSTDAll = 0;
                double SelectionTimeSTDAll = 0;
                double KLMDiffSTDAll = 0;
                double KLMRatioSTDAll = 0;

                double stdRawTotalTimeAll = 0;
                double stdRawYMouseVelocityAll = 0;
                double stdRawYMouseAccelerationAll = 0;
                double stdRawDwellTimeAll = 0;
                double stdRawAveDwellTimeAll = 0;
                double stdRawNrItemsAll = 0;
                double stdRawUniqueItemsAll = 0;
                double stdRawSelectionTimeAll = 0;
                double stdRawKLMDiffAll = 0;
                double stdRawKLMRatioAll = 0;

                #endregion


                #region Mean Variables ALL USERS

                    decimal meanRawTotalTimeAll = 0;
                    decimal meanRawYMouseVelocityAll = 0;
                    decimal meanRawYMouseAccelerationAll = 0;
                    decimal meanRawDwellTimeAll = 0;
                    decimal meanRawAveDwellTimeAll = 0;
                    decimal meanRawNrItemsAll = 0;
                    decimal meanRawUniqueItemsAll = 0;
                    decimal meanRawSelectionTimeAll = 0;
                    decimal meanRawKLMDiffAll = 0;
                    decimal meanRawKLMRatioAll = 0;

                #endregion


                #region XML Variables

                    ArrayList arrayPFsUser = (ArrayList)this.getArrayUserModelComboBoxXML(UID, StoredProcedueName, DisplaySol);
                    ArrayList arrayPFsExperts = (ArrayList)this.getArrayUserModelComboBoxXMLExperts(StoredProcedueNameExperts, DisplaySol);

                    XmlDocument docUser = new XmlDocument();
                    String XMLstringUser = "";

                    XmlDocument docExperts = new XmlDocument();
                    String XMLstringExperts = "";

                #endregion



                int TotalIncAllUsers = arrayPFsUser.Count + arrayPFsExperts.Count;



                #region Calculate SUM of Raw Values USER

                    for (int i = 0; i <= arrayPFsUser.Count - 1; i++)
                    {
                        XMLstringUser = arrayPFsUser[i].ToString();
                        docUser.LoadXml(XMLstringUser);

                        InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                        LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                        SumTotalTimeUser += Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[0].InnerText);
                        SumYMouseVelocityUser += Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[1].InnerText);
                        SumYMouseAccelerationUser += Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[2].InnerText);
                        SumDwellTimeUser += Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[3].InnerText);

                        InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                        SumAveDwellTimeUser += Convert.ToDecimal(InteractionTechn.ChildNodes[0].InnerText);
                        SumNrItemsUser += Convert.ToDecimal(InteractionTechn.ChildNodes[1].InnerText);
                        SumUniqueItemsUser += Convert.ToDecimal(InteractionTechn.ChildNodes[2].InnerText);
                        SumSelectionTimeUser += Convert.ToDecimal(InteractionTechn.ChildNodes[3].InnerText);

                        PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                        SumKLMDiffUser += Convert.ToDecimal(PerformanceM.ChildNodes[0].InnerText);
                        SumKLMRatioUser += Convert.ToDecimal(PerformanceM.ChildNodes[1].InnerText);

                    }


                #endregion



                #region Calculate MEAN of Raw Values All USERS

                    meanRawTotalTimeAll = (SumPF01TotalTime + SumTotalTimeUser) / TotalIncAllUsers;
                    meanRawYMouseVelocityAll = (SumPF02YMouseVelocity + SumYMouseVelocityUser) / TotalIncAllUsers;
                    meanRawYMouseAccelerationAll = (SumPF03YMouseAcceleration + SumYMouseAccelerationUser) / TotalIncAllUsers;
                    meanRawDwellTimeAll = (SumPF04DwellTime + SumDwellTimeUser) / TotalIncAllUsers;
                    meanRawAveDwellTimeAll = (SumPF05AverageDwellTime + SumAveDwellTimeUser) / TotalIncAllUsers;
                    meanRawNrItemsAll = (SumPF06NrItemsVisited + SumNrItemsUser) / TotalIncAllUsers;
                    meanRawUniqueItemsAll = (SumPF07UniqueItemsVisited + SumUniqueItemsUser) / TotalIncAllUsers;
                    meanRawSelectionTimeAll = (SumPF08SelectionTime + SumSelectionTimeUser) / TotalIncAllUsers;
                    meanRawKLMDiffAll = (SumPF09KLMDifference + SumKLMDiffUser) / TotalIncAllUsers;
                    meanRawKLMRatioAll = (SumPF10KLMRatio + SumKLMRatioUser) / TotalIncAllUsers;

                #endregion



                #region Calculate STD Dev of Raw Values USER

                    //STD = SQUARE ROOT (AUTOSUM (Raw value = Raw mean)SQUARED)/(n-1)

                    //Needed for Std Dev of User
                    for (int i = 0; i <= arrayPFsUser.Count - 1; i++)
                    {
                        XMLstringUser = arrayPFsUser[i].ToString();
                        docUser.LoadXml(XMLstringUser);

                        InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                        LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                        TotalTimeSTDAll += ((Convert.ToDouble(LowlevelMotionCharact.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawTotalTimeAll)) * (Convert.ToDouble(LowlevelMotionCharact.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawTotalTimeAll)));
                        YMouseVelocitySTDAll += ((Convert.ToDouble(LowlevelMotionCharact.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawYMouseVelocityAll)) * (Convert.ToDouble(LowlevelMotionCharact.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawYMouseVelocityAll)));
                        YMouseAccelerationSTDAll += ((Convert.ToDouble(LowlevelMotionCharact.ChildNodes[2].InnerText) - Convert.ToDouble(meanRawYMouseAccelerationAll)) * (Convert.ToDouble(LowlevelMotionCharact.ChildNodes[2].InnerText) - Convert.ToDouble(meanRawYMouseAccelerationAll)));
                        DwellTimeSTDAll += ((Convert.ToDouble(LowlevelMotionCharact.ChildNodes[3].InnerText) - Convert.ToDouble(meanRawDwellTimeAll)) * (Convert.ToDouble(LowlevelMotionCharact.ChildNodes[3].InnerText) - Convert.ToDouble(meanRawDwellTimeAll)));

                        InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                        AveDwellTimeSTDAll += ((Convert.ToDouble(InteractionTechn.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawDwellTimeAll)) * (Convert.ToDouble(InteractionTechn.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawDwellTimeAll)));
                        NrItemsSTDAll += ((Convert.ToDouble(InteractionTechn.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawNrItemsAll)) * (Convert.ToDouble(InteractionTechn.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawNrItemsAll)));
                        UniqueItemsSTDAll += ((Convert.ToDouble(InteractionTechn.ChildNodes[2].InnerText) - Convert.ToDouble(meanRawUniqueItemsAll)) * (Convert.ToDouble(InteractionTechn.ChildNodes[2].InnerText) - Convert.ToDouble(meanRawUniqueItemsAll)));
                        SelectionTimeSTDAll += ((Convert.ToDouble(InteractionTechn.ChildNodes[3].InnerText) - Convert.ToDouble(meanRawSelectionTimeAll)) * (Convert.ToDouble(InteractionTechn.ChildNodes[3].InnerText) - Convert.ToDouble(meanRawSelectionTimeAll)));

                        PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                        KLMDiffSTDAll += ((Convert.ToDouble(PerformanceM.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawKLMDiffAll)) * (Convert.ToDouble(PerformanceM.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawKLMDiffAll)));
                        KLMRatioSTDAll += ((Convert.ToDouble(PerformanceM.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawKLMRatioAll)) * (Convert.ToDouble(PerformanceM.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawKLMRatioAll)));
                    }


                    //Needed for Std Dev of All Experts
                    for (int i = 0; i <= arrayPFsExperts.Count - 1; i++)
                    {
                        XMLstringExperts = arrayPFsExperts[i].ToString();
                        docExperts.LoadXml(XMLstringExperts);

                        InteractionFeatures = (XmlElement)docExperts.DocumentElement.FirstChild;

                        LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                        TotalTimeSTDAll += ((Convert.ToDouble(LowlevelMotionCharact.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawTotalTimeAll)) * (Convert.ToDouble(LowlevelMotionCharact.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawTotalTimeAll)));
                        YMouseVelocitySTDAll += ((Convert.ToDouble(LowlevelMotionCharact.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawYMouseVelocityAll)) * (Convert.ToDouble(LowlevelMotionCharact.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawYMouseVelocityAll)));
                        YMouseAccelerationSTDAll += ((Convert.ToDouble(LowlevelMotionCharact.ChildNodes[2].InnerText) - Convert.ToDouble(meanRawYMouseAccelerationAll)) * (Convert.ToDouble(LowlevelMotionCharact.ChildNodes[2].InnerText) - Convert.ToDouble(meanRawYMouseAccelerationAll)));
                        DwellTimeSTDAll += ((Convert.ToDouble(LowlevelMotionCharact.ChildNodes[3].InnerText) - Convert.ToDouble(meanRawDwellTimeAll)) * (Convert.ToDouble(LowlevelMotionCharact.ChildNodes[3].InnerText) - Convert.ToDouble(meanRawDwellTimeAll)));

                        InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                        AveDwellTimeSTDAll += ((Convert.ToDouble(InteractionTechn.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawDwellTimeAll)) * (Convert.ToDouble(InteractionTechn.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawDwellTimeAll)));
                        NrItemsSTDAll += ((Convert.ToDouble(InteractionTechn.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawNrItemsAll)) * (Convert.ToDouble(InteractionTechn.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawNrItemsAll)));
                        UniqueItemsSTDAll += ((Convert.ToDouble(InteractionTechn.ChildNodes[2].InnerText) - Convert.ToDouble(meanRawUniqueItemsAll)) * (Convert.ToDouble(InteractionTechn.ChildNodes[2].InnerText) - Convert.ToDouble(meanRawUniqueItemsAll)));
                        SelectionTimeSTDAll += ((Convert.ToDouble(InteractionTechn.ChildNodes[3].InnerText) - Convert.ToDouble(meanRawSelectionTimeAll)) * (Convert.ToDouble(InteractionTechn.ChildNodes[3].InnerText) - Convert.ToDouble(meanRawSelectionTimeAll)));

                        PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                        KLMDiffSTDAll += ((Convert.ToDouble(PerformanceM.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawKLMDiffAll)) * (Convert.ToDouble(PerformanceM.ChildNodes[0].InnerText) - Convert.ToDouble(meanRawKLMDiffAll)));
                        KLMRatioSTDAll += ((Convert.ToDouble(PerformanceM.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawKLMRatioAll)) * (Convert.ToDouble(PerformanceM.ChildNodes[1].InnerText) - Convert.ToDouble(meanRawKLMRatioAll)));
                    }

                    //std deviation = sqrt(sum((value - mean) 2 ) / N-1) 

                    #region std

                        stdRawTotalTimeAll = Math.Sqrt(TotalTimeSTDAll / (TotalIncAllUsers - 1));
                        stdRawYMouseVelocityAll = Math.Sqrt(YMouseVelocitySTDAll / (TotalIncAllUsers - 1));
                        stdRawYMouseAccelerationAll = Math.Sqrt(YMouseAccelerationSTDAll / (TotalIncAllUsers - 1));
                        stdRawDwellTimeAll = Math.Sqrt(DwellTimeSTDAll / (TotalIncAllUsers - 1));
                        stdRawAveDwellTimeAll = Math.Sqrt(AveDwellTimeSTDAll / (TotalIncAllUsers - 1));
                        stdRawNrItemsAll = Math.Sqrt(NrItemsSTDAll / (TotalIncAllUsers - 1));
                        stdRawUniqueItemsAll = Math.Sqrt(UniqueItemsSTDAll / (TotalIncAllUsers - 1));
                        stdRawSelectionTimeAll = Math.Sqrt(SelectionTimeSTDAll / (TotalIncAllUsers - 1));
                        stdRawKLMDiffAll = Math.Sqrt(KLMDiffSTDAll / (TotalIncAllUsers - 1));
                        stdRawKLMRatioAll = Math.Sqrt(KLMRatioSTDAll / (TotalIncAllUsers - 1));

                    #endregion


                #endregion



                #region T-scores Variables

                        //needed for std dev
                decimal TotalTimeTScore = 0;
                decimal YMouseVelocityTScore = 0;
                decimal YMouseAccelerationTScore = 0;
                decimal DwellTimeTScore = 0;
                decimal AveDwellTimeTScore = 0;
                decimal NrItemsTScore = 0;
                decimal UniqueItemsTScore = 0;
                decimal SelectionTimeTScore = 0;
                decimal KLMDiffTScore = 0;
                decimal KLMRatioTScore = 0;

                decimal TotalTimeWeight = 1;
                decimal YMouseVelocityWeight = 0.11m;
                decimal YMouseAccelerationWeight = 0.11m;
                decimal DwellTimeWeight = 0.5m;
                decimal AveDwellTimeWeight = 0.33m;
                decimal NrItemsWeight = 0.167m;
                decimal UniqueItemsWeight = 0.143m;
                decimal SelectionTimeWeight = 0.33m;
                decimal KLMDiffWeight = 0.2m;
                decimal KLMRatioWeight = 0.125m;

                decimal PFtotalWeight = 3.015m;

                #endregion



                #region Calculate IM Values


                    decimal IMTScore = 0;
                    ArrayList arrayIMValues = new ArrayList();


                    for (int i = 0; i <= arrayPFsUser.Count - 1; i++)
                    {
                        XMLstringUser = arrayPFsUser[i].ToString();
                        docUser.LoadXml(XMLstringUser);

                        InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                        LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];

                        //Total Time T-Score
                        if (stdRawTotalTimeAll== 0)
                        {
                            TotalTimeTScore = 50 - (((Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[0].InnerText) - meanRawTotalTimeAll) * 10) / 1);
                        }
                        else
                        {
                            TotalTimeTScore = 50 - (((Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[0].InnerText) - meanRawTotalTimeAll) * 10) / Convert.ToDecimal(stdRawTotalTimeAll));
                        }

                        //Y Mouse Velocity T-Score
                        if (stdRawYMouseVelocityAll == 0)
                        {
                            YMouseVelocityTScore = 50 + (((Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[1].InnerText) - meanRawYMouseVelocityAll) * 10) / 1);
                        }
                        else
                        {
                            YMouseVelocityTScore = 50 + (((Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[1].InnerText) - meanRawYMouseVelocityAll) * 10) / Convert.ToDecimal(stdRawYMouseVelocityAll));

                        }

                        //Y Mouse Acceleration T-Score
                        if (stdRawYMouseAccelerationAll == 0)
                        {
                            YMouseAccelerationTScore = 50 + (((Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[2].InnerText) - meanRawYMouseAccelerationAll) * 10) / 1);
                        }
                        else
                        {
                            YMouseAccelerationTScore = 50 + (((Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[2].InnerText) - meanRawYMouseAccelerationAll) * 10) / Convert.ToDecimal(stdRawYMouseAccelerationAll));

                        }

                        //Dwell Time T-Score
                        if (stdRawDwellTimeAll == 0)
                        {
                            DwellTimeTScore = 50 - (((Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[3].InnerText) - meanRawDwellTimeAll) * 10) / 1);
                        }
                        else
                        {
                            DwellTimeTScore = 50 - (((Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[3].InnerText) - meanRawDwellTimeAll) * 10) / Convert.ToDecimal(stdRawDwellTimeAll));

                        }


                        InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];

                        //Average Dwell Time T-Score
                        if (stdRawAveDwellTimeAll == 0)
                        {
                            AveDwellTimeTScore = 50 - (((Convert.ToDecimal(InteractionTechn.ChildNodes[0].InnerText) - meanRawAveDwellTimeAll) * 10) / 1);
                        }
                        else
                        {
                            AveDwellTimeTScore = 50 - (((Convert.ToDecimal(InteractionTechn.ChildNodes[0].InnerText) - meanRawAveDwellTimeAll) * 10) / Convert.ToDecimal(stdRawAveDwellTimeAll));
                        }

                        //Nr Items T-Score
                        if (stdRawNrItemsAll == 0)
                        {
                            NrItemsTScore = 50 - (((Convert.ToDecimal(InteractionTechn.ChildNodes[1].InnerText) - meanRawNrItemsAll) * 10) / 1);
                        }
                        else
                        {
                            NrItemsTScore = 50 - (((Convert.ToDecimal(InteractionTechn.ChildNodes[1].InnerText) - meanRawNrItemsAll) * 10) / Convert.ToDecimal(stdRawNrItemsAll));

                        }

                        //Unique Items T-Score
                        if (stdRawUniqueItemsAll == 0)
                        {
                            UniqueItemsTScore = 50 - (((Convert.ToDecimal(InteractionTechn.ChildNodes[2].InnerText) - meanRawUniqueItemsAll) * 10) / 1);
                        }
                        else
                        {
                            UniqueItemsTScore = 50 - (((Convert.ToDecimal(InteractionTechn.ChildNodes[2].InnerText) - meanRawUniqueItemsAll) * 10) / Convert.ToDecimal(stdRawUniqueItemsAll));

                        }

                        //Selection Time T-Score
                        if (stdRawSelectionTimeAll == 0)
                        {
                            SelectionTimeTScore = 50 - (((Convert.ToDecimal(InteractionTechn.ChildNodes[3].InnerText) - meanRawSelectionTimeAll) * 10) / 1);
                        }
                        else
                        {
                            SelectionTimeTScore = 50 - (((Convert.ToDecimal(InteractionTechn.ChildNodes[3].InnerText) - meanRawSelectionTimeAll) * 10) / Convert.ToDecimal(stdRawSelectionTimeAll));

                        }


                        PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];

                        //KLM Diff T-Score
                        if (stdRawKLMDiffAll == 0)
                        {
                            KLMDiffTScore = 50 - (((Convert.ToDecimal(PerformanceM.ChildNodes[0].InnerText) - meanRawKLMDiffAll) * 10) / 1);
                        }
                        else
                        {
                            KLMDiffTScore = 50 - (((Convert.ToDecimal(PerformanceM.ChildNodes[0].InnerText) - meanRawKLMDiffAll) * 10) / Convert.ToDecimal(stdRawKLMDiffAll));

                        }

                        //KLM Ratio T-Score
                        if (stdRawKLMRatioAll == 0)
                        {
                            KLMRatioTScore = 50 + (((Convert.ToDecimal(PerformanceM.ChildNodes[1].InnerText) - meanRawKLMRatioAll) * 10) / 1);
                        }
                        else
                        {
                            KLMRatioTScore = 50 + (((Convert.ToDecimal(PerformanceM.ChildNodes[1].InnerText) - meanRawKLMRatioAll) * 10) / Convert.ToDecimal(stdRawKLMRatioAll));

                        }


                        IMTScore = (((Decimal.Round(TotalTimeTScore, 2) * TotalTimeWeight) + (Decimal.Round(YMouseVelocityTScore, 2) * YMouseVelocityWeight) + (Decimal.Round(YMouseAccelerationTScore, 2) * YMouseAccelerationWeight) + (Decimal.Round(DwellTimeTScore, 2) * DwellTimeWeight) + (Decimal.Round(AveDwellTimeTScore, 2) * AveDwellTimeWeight) + (Decimal.Round(NrItemsTScore, 2) * NrItemsWeight) + (Decimal.Round(UniqueItemsTScore, 2) * UniqueItemsWeight) + (Decimal.Round(SelectionTimeTScore, 2) * SelectionTimeWeight) + (Decimal.Round(KLMDiffTScore, 2) * KLMDiffWeight) + (Decimal.Round(KLMRatioTScore, 2) * KLMRatioWeight)) / PFtotalWeight);

                        arrayIMValues.Add(Decimal.Round(IMTScore, 2));
                    }


                #endregion


                return arrayIMValues;
            }



            public ArrayList getTotalTaskTimesTScores(string uID, string DisplaySol, int TotalforMeanExperts)
            {

                ArrayList arrayTotalTaskTimes = sp.getTotalTaskTime(uID,DisplaySol);
                ArrayList arrayTotalTaskTimesAExperts = sp.getTotalTaskTimeAll(DisplaySol);

                int TotalforMeanUser = 0;
                double TotalForSTD = 0;
                decimal mean = 0;
                double std = 0;
                decimal TScore = 0;
                ArrayList arrayTValues = new ArrayList();

                int CountAll = 8 + arrayTotalTaskTimes.Count;

                //CalculateMean
                #region MEAN

                    for (int i = 0; i <= arrayTotalTaskTimes.Count - 1; i++)
                    {
                        TotalforMeanUser += Convert.ToInt32(arrayTotalTaskTimes[i]);
                    }

                    mean = (TotalforMeanExperts + TotalforMeanUser) / CountAll;
                
                #endregion


                //CalculateSTDev
                #region STDEV

                //For users
                    for (int i = 0; i <= arrayTotalTaskTimes.Count - 1; i++)
                    {
                        TotalForSTD += ((Convert.ToInt32(arrayTotalTaskTimes[i]) - Convert.ToDouble(mean)) * (Convert.ToInt32(arrayTotalTaskTimes[i]) - Convert.ToDouble(mean)));
                    }

                //For Experts
                    for (int i = 0; i <= arrayTotalTaskTimesAExperts.Count - 1; i++)
                    {
                        TotalForSTD += ((Convert.ToInt32(arrayTotalTaskTimesAExperts[i]) - Convert.ToDouble(mean)) * (Convert.ToInt32(arrayTotalTaskTimesAExperts[i]) - Convert.ToDouble(mean)));
                    }

                    std = Math.Sqrt(TotalForSTD / (CountAll - 1));

                #endregion


                //CalculateTScore
                #region T-Score

                    decimal RawValue = 0;

                    for (int i = 0; i <= arrayTotalTaskTimes.Count - 1; i++)
                    {
                        RawValue = Convert.ToDecimal(arrayTotalTaskTimes[i]);
                        if (std == 0)
                        {
                            TScore = 50 - (((RawValue - mean) * 10) / 1);
                        }
                        else
                        {
                            TScore = 50 - (((RawValue - mean) * 10) / Convert.ToDecimal(std));

                        }

                        arrayTValues.Add(Decimal.Round(TScore,2));
                    }

                    
                #endregion

                return arrayTValues;
            }



            public void CalcFinalT(string uID)
            {

                ArrayList IMSearchCustYes = this.getIMs(uID, "getUserProfileIMSearchCustAE","getUserProfileIMSearchCustAEExperts", "Yes", 19.3m, 961.13m, 1391.68m, 12.6m, 12.6m, 8, 8, 19.3m, 16.5m, 21.14m);
                ArrayList IMServiceNameYes = this.getIMs(uID, "getUserProfileIMServiceNameAE", "getUserProfileIMServiceNameAEExperts", "Yes", 55.6m, 321.26m, 107.06m, 19.4m, 13.48m, 11, 11, 42.1m, 24.1m, 6.18m);
                ArrayList IMCallTypeYes = this.getIMs(uID, "getUserProfileIMCallTypeAE", "getUserProfileIMCallTypeAEExperts","Yes",  62.7m, 357.83m, 102, 17.1m, 17.1m, 8, 8, 46.7m, 28.3m, 5.65m);
                ArrayList IMPriorityYes = this.getIMs(uID, "getUserProfileIMPriorityAE",  "getUserProfileIMPriorityAEExperts","Yes", 9.9m, 470.36m, 645.27m, 1.1m, .55m, 9, 9, 8.8m, 12.4m, 24.25m);
                ArrayList IMSourceYes = this.getIMs(uID, "getUserProfileIMSourceAE",  "getUserProfileIMSourceAEExperts","Yes", 30.8m, 334.594m, 107.604m, 12.6m, 12.6m, 8, 8, 30.8m, 11.6m, 6.37m);
                ArrayList IMCampusYes = this.getIMs(uID, "getUserProfileIMCampusAE",  "getUserProfileIMCampusAEExperts", "Yes",35.7m, 343.31m, 220.43m, 21.5m, 21.5m, 8, 8, 35.7m, 25.8m, 11.19m);
                ArrayList IMContactYes = this.getIMs(uID, "getUserProfileIMContactAE",  "getUserProfileIMContactAEExperts","Yes", 20.8m, 500.07m, 231.99m, 4.7m, 4.7m, 8, 8, 20.8m, 7.7m, 10.24m);
                ArrayList IMCauseYes = this.getIMs(uID, "getUserProfileIMCauseAE", "getUserProfileIMCauseAEExperts","Yes",  42.3m, 249.45m, 71.5m, 25, 25, 8, 8, 42.3m, 23.5m, 5.27m);
                ArrayList IMResolvedYes = this.getIMs(uID, "getUserProfileIMResolvedAE",  "getUserProfileIMResolvedAEExperts", "Yes",18.8m, 311.06m, 277, 7.3m, 7.3m, 8, 8, 18.8m, 14.6m, 16);
                ArrayList TimeTScoresYes = (ArrayList)this.getTotalTaskTimesTScores(uID,"Yes",1876);


                ArrayList IMSearchCustNo = this.getIMs(uID, "getUserProfileIMSearchCustAE", "getUserProfileIMSearchCustAEExperts","No",  1.29m, 198.80m, 353.17m, 1.25m, 1.25m, 1.38m, 0.63m, 0.94m, 1.71m, 4.10m);
                ArrayList IMServiceNameNo = this.getIMs(uID, "getUserProfileIMServiceNameAE",  "getUserProfileIMServiceNameAEExperts","No", 20.7m, 378.88m, 159.9m, 6.9m, 6.9m, 8.0m, 8.0m, 20.7m, 5.1m, 8.88m);
                ArrayList IMCallTypeNo = this.getIMs(uID, "getUserProfileIMCallTypeAE",  "getUserProfileIMCallTypeAEExperts", "No",54.10m, 205.97m, 57.22m, 35.2m, 32, 9, 9, 46.9m, 27.2m, 4.64m);
                ArrayList IMPriorityNo = this.getIMs(uID, "getUserProfileIMPriorityAE",  "getUserProfileIMPriorityAEExperts","No", 73.7m, 166.65m, 103.72m, 31.3m, 28.6m, 9, 9, 56.4m, 40, 7.13m);
                ArrayList IMSourceNo = this.getIMs(uID, "getUserProfileIMSourceAE", "getUserProfileIMSourceAEExperts","No",  42.10m, 179.73m, 51.25m, 27.6m, 27.6m, 8, 8, 42.1m, 22.1m, 5.57m);
                ArrayList IMCampusNo = this.getIMs(uID, "getUserProfileIMCampusAE", "getUserProfileIMCampusAEExperts","No",  42.3m, 396.38m, 295.14m, 25.8m, 15.87m, 14, 10, 21.7m, 14.3m, 12.51m);
                ArrayList IMContactNo = this.getIMs(uID, "getUserProfileIMContactAE",  "getUserProfileIMContactAEExperts","No", 95.6m, 492.48m, 184.6m, 28.1m, 28.1m, 8, 8, 44.8m, 28.9m, 6.69m);
                ArrayList TimeTScoresNo = (ArrayList)this.getTotalTaskTimesTScores(uID, "No", 1714);


                ArrayList TotalTScores = new ArrayList();
   
                decimal IMSearchCustWeight = 0.125m;
                decimal IMServiceNameWeight = 0.5m;
                decimal IMCallTypeWeight = 0.5m;
                decimal IMPriorityWeight = 0.11m;
                decimal IMSourceWeight = 0.1m;
                decimal IMCampusWeight = 0.2m;
                decimal IMContactWeight = 0.2m;
                decimal IMCauseWeight = 0.25m;
                decimal IMResolvedWeight = 0.2m;
                decimal TotalTaskTimesWeight = 1;

                decimal IMtotalWeight = 3.185m;
                decimal IMtotalWeightNoSol = 2.735m;

                int countYes = TimeTScoresYes.Count;
                int countNo = TimeTScoresNo.Count;
              //  int incCauseAndResolved = 0;
                decimal TScore = 0;

               // ArrayList DisplaySOl = (ArrayList)sp.getDisplaySolution(uID);

                for (int i = 0; i <= countYes - 1; i++)
                {

                    TScore = ((Decimal.Round((decimal)IMSearchCustYes[i], 2) * IMSearchCustWeight) + (Decimal.Round((decimal)IMServiceNameYes[i], 2) * IMServiceNameWeight) + (Decimal.Round((decimal)IMCallTypeYes[i], 2) * IMCallTypeWeight) + (Decimal.Round((decimal)IMPriorityYes[i], 2) * IMPriorityWeight) + (Decimal.Round((decimal)IMSourceYes[i], 2) * IMSourceWeight) + (Decimal.Round((decimal)IMCampusYes[i], 2) * IMCampusWeight) + (Decimal.Round((decimal)IMContactYes[i], 2) * IMContactWeight) + (Decimal.Round((decimal)IMCauseYes[i], 2) * IMCauseWeight) + (Decimal.Round((decimal)IMResolvedYes[i], 2) * IMResolvedWeight) + (Decimal.Round((decimal)TimeTScoresYes[i], 2) * TotalTaskTimesWeight)) / IMtotalWeight;
                        arraySol.Add(Decimal.Round(TScore, 2));

                        //TotalTScores.Add(((IMSearchCust[i] * IMSearchCustWeight) + ((double)IMServiceName[i] * IMServiceNameWeight) + ((double)IMCallType[i] * IMCallTypeWeight) + ((double)IMPriority[i] * IMPriorityWeight) + ((double)IMSource[i] * IMSourceWeight) + ((double)IMCampus[i] * IMCampusWeight) + ((double)IMContact[i] * IMContactWeight) + ((double)IMCause[i] * IMCauseWeight) + ((double)IMResolved[i] * IMResolvedWeight) + ((double)TimeTScores[i] * TotalTaskTimesWeight)) / IMtotalWeight);

                }


                for (int i = 0; i <= countNo - 1; i++)
                {

                   TScore = ((Decimal.Round((decimal)IMSearchCustNo[i], 2) * IMSearchCustWeight) + (Decimal.Round((decimal)IMServiceNameNo[i], 2) * IMServiceNameWeight) + (Decimal.Round((decimal)IMCallTypeNo[i], 2) * IMCallTypeWeight) + (Decimal.Round((decimal)IMPriorityNo[i], 2) * IMPriorityWeight) + (Decimal.Round((decimal)IMSourceNo[i], 2) * IMSourceWeight) + (Decimal.Round((decimal)IMCampusNo[i], 2) * IMCampusWeight) + (Decimal.Round((decimal)IMContactNo[i], 2) * IMContactWeight) +  (Decimal.Round((decimal)TimeTScoresNo[i], 2) * TotalTaskTimesWeight)) / IMtotalWeightNoSol;
                   arrayNoSol.Add(Decimal.Round(TScore, 2));

                    //TotalTScores.Add(((IMSearchCust[i] * IMSearchCustWeight) + ((double)IMServiceName[i] * IMServiceNameWeight) + ((double)IMCallType[i] * IMCallTypeWeight) + ((double)IMPriority[i] * IMPriorityWeight) + ((double)IMSource[i] * IMSourceWeight) + ((double)IMCampus[i] * IMCampusWeight) + ((double)IMContact[i] * IMContactWeight) + ((double)IMCause[i] * IMCauseWeight) + ((double)IMResolved[i] * IMResolvedWeight) + ((double)TimeTScores[i] * TotalTaskTimesWeight)) / IMtotalWeight);

                }


            }


            public ArrayList FinalTNoSolution(string userID)
            {
                return arrayNoSol;
            }

            public ArrayList FinalTSolution(string userID)
            {
                return arraySol;
            }


            public bool isExpert(string UID)
            {
                int MaxTasksDone = sp.getDisplaySolution(UID).Count;

                decimal ExpertQuartileTScoreNo = 51; // based on her pilot study
                decimal ExpertQuartileTScoreYes = 51; // based on her pilot study

                this.CalcFinalT(UID);
                ArrayList TFinalScoresYes = this.arraySol;
                ArrayList TFinalScoresNo = this.arrayNoSol;

                decimal sumYes = 0;
                decimal sumNo = 0;

                decimal aveYes = 0;
                decimal aveNo = 0;

                for (int i = 0; i <= TFinalScoresYes.Count - 1; i++)
                {
                    sumYes += (decimal)TFinalScoresYes[i];
                }

                for (int i = 0; i <= TFinalScoresNo.Count - 1; i++)
                {
                    sumNo += (decimal)TFinalScoresNo[i];
                }

                if (TFinalScoresYes.Count == 0)
                    return false;
                aveYes = sumYes / TFinalScoresYes.Count;
                //aveNo = sumNo / TFinalScoresNo.Count;

                if (MaxTasksDone > 7)
                {
                    return true;
                }
                else if ((aveYes >= ExpertQuartileTScoreYes) && (MaxTasksDone > 3)) 
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }


        #endregion



        #region WRITE TO EXCEL


            public void getResultsPerUser(string UserID, string StoredProcedueName)
            {

                //ArrayList arrayIMsUser = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, StoredProcedueName);
                //XmlDocument docUser = new XmlDocument();
                //String XMLstringUser = "";

                //for (int i = 0; i <= arrayIMsUser.Count - 1; i++)
                //{
                //    XMLstringUser = arrayIMsUser[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    SumTotalTimeUser += Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[0].InnerText);
                //    SumYMouseVelocityUser += Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[1].InnerText);
                //    SumYMouseAccelerationUser += Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[2].InnerText);
                //    SumDwellTimeUser += Convert.ToDecimal(LowlevelMotionCharact.ChildNodes[3].InnerText);

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    SumAveDwellTimeUser += Convert.ToDecimal(InteractionTechn.ChildNodes[0].InnerText);
                //    SumNrItemsUser += Convert.ToDecimal(InteractionTechn.ChildNodes[1].InnerText);
                //    SumUniqueItemsUser += Convert.ToDecimal(InteractionTechn.ChildNodes[2].InnerText);
                //    SumSelectionTimeUser += Convert.ToDecimal(InteractionTechn.ChildNodes[3].InnerText);

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    SumKLMDiffUser += Convert.ToDecimal(PerformanceM.ChildNodes[0].InnerText);
                //    SumKLMRatioUser += Convert.ToDecimal(PerformanceM.ChildNodes[1].InnerText);

                //}
            }



            public void SaveToExcel(string UserID)
            {
                //Microsoft.Office.Interop.Excel._Application excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                //excelApp.Visible = true;  // Makes Excel visible to the user.

                //// The following line adds a new workbook
                //Microsoft.Office.Interop.Excel.Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

                //// The following code opens an existing workbook
                //string workbookPath = "C:/Users/Emile/Documents/NMMU/Implementation/FINAL PROJECT/BeeWare.xlsx";  // Add your own path here
                //Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

                //// The following gets the Worksheets collection
                //Microsoft.Office.Interop.Excel.Sheets excelSheets = excelWorkbook.Worksheets;

                //// The following gets Sheet1 for editing
                //string currentSheet = "Sheet1";
                //Microsoft.Office.Interop.Excel.Worksheet excelWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(currentSheet);


                ////// The following gets cell A1 for editing
                ////Microsoft.Office.Interop.Excel.Range excelCell = (Microsoft.Office.Interop.Excel.Range)excelWorksheet.get_Range("A1", "A1");

                ////// The following sets cell A1's value to "Hi There"
                ////excelCell.Value2 = "Hi There";

                ////excelWorksheet.Cells[1, 1] = "Boo";

                ////excelWorksheet.Cells[1, 2] = "Pass";


                //ArrayList arrayIMSearchCustomer = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMSearchCust");
                //ArrayList arrayIMServiceName= (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMServiceNameAE");
                //ArrayList arrayIMCallType = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMCallType");
                //ArrayList arrayIMPriority = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMPriorityAE");
                //ArrayList arrayIMSource = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMSource");
                //ArrayList arrayIMCampus = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMCampus");
                //ArrayList arrayIMContact = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMContactAE");
                //ArrayList arrayIMCause = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMCauseAE");
                //ArrayList arrayIMResolved = (ArrayList)this.getArrayUserModelXML_Analysis(UserID, "ANALYSISgetUserProfileIMResolved");

                //XmlDocument docUser = new XmlDocument();
                //String XMLstringUser = "";

                //int row = 1;
                //int col = 1;

                //for (int i = 0; i <= arrayIMSearchCustomer.Count - 1; i++)
                //{
                //    //IM 1
                //    XMLstringUser = arrayIMSearchCustomer[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                //    col++;

                //    //IM 2
                //    XMLstringUser = arrayIMServiceName[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                //    col++;

                //    //IM 3
                //    XMLstringUser = arrayIMCallType[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                //    col++;

                //    //IM 4
                //    XMLstringUser = arrayIMPriority[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                //    col++;

                //    //IM 5
                //    XMLstringUser = arrayIMSource[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                //    col++;

                //    //IM 6
                //    XMLstringUser = arrayIMCampus[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                //    col++;

                //    //IM 7
                //    XMLstringUser = arrayIMContact[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                //    col++;

                //    //IM 8
                //    XMLstringUser = arrayIMCause[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                //    col++;

                //    //IM 9
                //    XMLstringUser = arrayIMResolved[i].ToString();
                //    docUser.LoadXml(XMLstringUser);

                //    InteractionFeatures = (XmlElement)docUser.DocumentElement.FirstChild;

                //    LowlevelMotionCharact = (XmlElement)InteractionFeatures.GetElementsByTagName("Low-levelMotionCharacteristics")[0];
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = LowlevelMotionCharact.ChildNodes[3].InnerText;
                //    col++;

                //    InteractionTechn = (XmlElement)InteractionFeatures.GetElementsByTagName("InteractionTechnique")[0];
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[2].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = InteractionTechn.ChildNodes[3].InnerText;
                //    col++;

                //    PerformanceM = (XmlElement)InteractionFeatures.GetElementsByTagName("PerformanceModels")[0];
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[0].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = PerformanceM.ChildNodes[1].InnerText;
                //    col++;
                //    excelWorksheet.Cells[row, col] = "";
                    
                //    col = 1;
                //    row++;
                //}

            }

        #endregion

    }
}
